

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/favicon.ico">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="xuehaoweng">
  <meta name="keywords" content="">
  
    <meta name="description" content="SkyWalking 是什么？官方摘要SkyWalking 是一个开源的 APM 系统，为云原生架构中的分布式系统提供监控、跟踪和诊断功能。 分布式追踪端到端分布式跟踪。服务拓扑分析、以服务为中心的可观察性和 API 仪表板。 您堆栈的代理Java、.Net Core、PHP、NodeJS、Golang、LUA、Rust、C++、客户端 JavaScript 和 Python 代理，具有积极的">
<meta property="og:type" content="article">
<meta property="og:title" content="Python 项目微服务链路追踪监控利器：SkyWalking 全景解析与实战应用">
<meta property="og:url" content="http://blog.xhweng.cn/2024/03/27/python_SkyWalking/index.html">
<meta property="og:site_name" content="有追求的开发者">
<meta property="og:description" content="SkyWalking 是什么？官方摘要SkyWalking 是一个开源的 APM 系统，为云原生架构中的分布式系统提供监控、跟踪和诊断功能。 分布式追踪端到端分布式跟踪。服务拓扑分析、以服务为中心的可观察性和 API 仪表板。 您堆栈的代理Java、.Net Core、PHP、NodeJS、Golang、LUA、Rust、C++、客户端 JavaScript 和 Python 代理，具有积极的">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://blog.xhweng.cn/img/file_img/skywalking.jpg">
<meta property="article:published_time" content="2024-03-27T03:09:31.000Z">
<meta property="article:modified_time" content="2024-03-27T03:12:47.437Z">
<meta property="article:author" content="xuehaoweng">
<meta property="article:tag" content="监控">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="http://blog.xhweng.cn/img/file_img/skywalking.jpg">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>Python 项目微服务链路追踪监控利器：SkyWalking 全景解析与实战应用 - 有追求的开发者</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"blog.xhweng.cn","root":"/","version":"1.9.7","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":"b3bbb822b3d2a5e2761107c03cf72b8c","google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  

  
    <!-- Baidu Analytics -->
    <script async>
      if (!Fluid.ctx.dnt) {
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?b3bbb822b3d2a5e2761107c03cf72b8c";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
      }
    </script>
  

  
    <!-- Google tag (gtag.js) -->
    <script async>
      if (!Fluid.ctx.dnt) {
        Fluid.utils.createScript("https://www.googletagmanager.com/gtag/js?id=", function() {
          window.dataLayer = window.dataLayer || [];
          function gtag() {
            dataLayer.push(arguments);
          }
          gtag('js', new Date());
          gtag('config', '');
        });
      }
    </script>
  

  

  

  

  



  
<meta name="generator" content="Hexo 7.0.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>有追求的开发者</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/" target="_self">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/" target="_self">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/" target="_self">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/" target="_self">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/" target="_self">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/bg/big.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Python 项目微服务链路追踪监控利器：SkyWalking 全景解析与实战应用"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2024-03-27 11:09" pubdate>
          2024年3月27日 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          2.5k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          21 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">Python 项目微服务链路追踪监控利器：SkyWalking 全景解析与实战应用</h1>
            
            
              <div class="markdown-body">
                
                <p><img src="https://files.mdnice.com/user/33721/765eec1d-a27a-4d05-b68a-33c3b2f8554b.jpeg" srcset="/img/loading.gif" lazyload alt="92569844684d8a59d2ab2db52b20cbac"></p>
<p><img src="https://files.mdnice.com/user/33721/cf3eca1e-6fc6-42d1-9a62-15ddff66fb77.png" srcset="/img/loading.gif" lazyload alt="image"></p>
<h1 id="SkyWalking-是什么？"><a href="#SkyWalking-是什么？" class="headerlink" title="SkyWalking 是什么？"></a>SkyWalking 是什么？</h1><h2 id="官方摘要"><a href="#官方摘要" class="headerlink" title="官方摘要"></a>官方摘要</h2><p><strong>SkyWalking</strong> 是一个开源的 APM 系统，为云原生架构中的分布式系统提供监控、跟踪和诊断功能。</p>
<h3 id="分布式追踪"><a href="#分布式追踪" class="headerlink" title="分布式追踪"></a>分布式追踪</h3><p>端到端分布式跟踪。服务拓扑分析、以服务为中心的可观察性和 API 仪表板。</p>
<h3 id="您堆栈的代理"><a href="#您堆栈的代理" class="headerlink" title="您堆栈的代理"></a>您堆栈的代理</h3><p>Java、.Net Core、PHP、NodeJS、Golang、LUA、Rust、C++、客户端 JavaScript 和 Python 代理，具有积极的开发和维护能力。</p>
<h3 id="eBPF-早期采用"><a href="#eBPF-早期采用" class="headerlink" title="eBPF 早期采用"></a>eBPF 早期采用</h3><p>Rover 代理充当由 eBPF 提供支持的监视器和分析器，用于监视 Kubernetes 部署并诊断 CPU 和网络性能。</p>
<h3 id="缩放"><a href="#缩放" class="headerlink" title="缩放"></a>缩放</h3><p>一个 SkyWalking 集群可以收集和分析超过 1000 亿个遥测数据。</p>
<h3 id="支持成熟的遥测生态系统"><a href="#支持成熟的遥测生态系统" class="headerlink" title="支持成熟的遥测生态系统"></a>支持成熟的遥测生态系统</h3><p>支持来自成熟生态系统的指标、跟踪和日志，例如 Zipkin、OpenTelemetry、Prometheus、Zabbix、Fluentd</p>
<h3 id="原生-APM-数据库"><a href="#原生-APM-数据库" class="headerlink" title="原生 APM 数据库"></a>原生 APM 数据库</h3><p>BanyanDB 是一个可观测性数据库，创建于 2022 年，旨在摄取、分析和存储遥测&#x2F;可观测数据。</p>
<h3 id="一致的指标聚合"><a href="#一致的指标聚合" class="headerlink" title="一致的指标聚合"></a>一致的指标聚合</h3><p>SkyWalking 原生计量格式和众所周知的计量格式（例如 OpenTelemetry、Telegraf、Zabbix）通过相同的脚本管道进行处理。</p>
<h3 id="日志管理管道"><a href="#日志管理管道" class="headerlink" title="日志管理管道"></a>日志管理管道</h3><p>通过脚本管道高性能支持日志格式化、提取指标、各种采样策略。</p>
<h3 id="警报和遥测管道"><a href="#警报和遥测管道" class="headerlink" title="警报和遥测管道"></a>警报和遥测管道</h3><p>支持以服务为中心、以部署为中心、以 API 为中心的报警规则设置。支持将警报和所有遥测数据转发给第三方。</p>
<h2 id="SkyWalking-介绍"><a href="#SkyWalking-介绍" class="headerlink" title="SkyWalking 介绍"></a>SkyWalking 介绍</h2><p>Apache Skywalking 是一款开源的应用程序性能监控工具，旨在帮助开发人员和 DevOps 团队监控分布式应用程序的性能。它可以帮助用户了解应用程序的运行情况，并通过可视化图形和数据报告，提供实时的指标和分析。</p>
<p>Skywalking 支持多种语言和框架，包括 Java、Go、Node.js 和 Python。它使用分布式追踪技术来监控应用程序内部和外部的所有调用，从而获得关于应用程序性能的完整见解。</p>
<p>Skywalking 提供了一系列强大的功能，包括性能监控、故障诊断和调试、数据分析等。它还提供了警报功能，当发生重要的性能问题时，可以向开发人员和 DevOps 团队发送通知。</p>
<p>Skywalking 还具有很好的可扩展性，可以与其他应用程序性能监控工具，如 Grafana 和 Elasticsearch 集成，从而提供更加强大的监控和分析能力。</p>
<p>总之，Apache Skywalking 是一款功能强大且易于使用的应用程序性能监控工具。它可以帮助开发人员和 DevOps 团队更好地了解应用程序的运行情况，并在发生性能问题时及时采取行动。</p>
<p>官网：skywalking.apache.org&#x2F;</p>
<p>下载：skywalking.apache.org&#x2F;downloads&#x2F;</p>
<p>Github：<a target="_blank" rel="noopener" href="https://github.com/apache/skywalking">https://github.com/apache/skywalking</a></p>
<p>文档：<a target="_blank" rel="noopener" href="https://skywalking.apache.org/docs/">https://skywalking.apache.org/docs/</a></p>
<p>中文文档：<a target="_blank" rel="noopener" href="https://skyapm.github.io/document-cn-translation-of-skywalking/">https://skyapm.github.io/document-cn-translation-of-skywalking/</a></p>
<h1 id="SkyWalking-在-Python-项目中的使用"><a href="#SkyWalking-在-Python-项目中的使用" class="headerlink" title="SkyWalking 在 Python 项目中的使用"></a>SkyWalking 在 Python 项目中的使用</h1><p><strong>SkyWalking Python Agent</strong> 支持 Apache SkyWalking 的 Python 代理为 Python 项目提供本机跟踪&#x2F;指标&#x2F;日志记录&#x2F;分析功能。</p>
<h2 id="部署-SkyWalking"><a href="#部署-SkyWalking" class="headerlink" title="部署 SkyWalking"></a>部署 SkyWalking</h2><p>部署 SkyWalking 需要三个组件 <strong>sky-elasticsearch</strong>，<strong>skywalking-oap</strong>，<strong>skywalking-ui</strong>.</p>
<p>采用 docker-compose 部署</p>
<figure class="highlight nestedtext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><code class="hljs nestedtext"><span class="hljs-attribute">version</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&#x27;3.5&#x27;</span><br><span class="hljs-attribute">services</span><span class="hljs-punctuation">:</span><br>  <span class="hljs-attribute">sky-elasticsearch</span><span class="hljs-punctuation">:</span><br>    <span class="hljs-attribute">image</span><span class="hljs-punctuation">:</span> <span class="hljs-string">elasticsearch:6.8.1</span><br>    <span class="hljs-attribute">container_name</span><span class="hljs-punctuation">:</span> <span class="hljs-string">sky-elasticsearch</span><br>    <span class="hljs-attribute">restart</span><span class="hljs-punctuation">:</span> <span class="hljs-string">always</span><br>    <span class="hljs-attribute">ports</span><span class="hljs-punctuation">:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">19200:9200</span><br>    <span class="hljs-attribute">environment</span><span class="hljs-punctuation">:</span><br>      <span class="hljs-attribute">discovery.type</span><span class="hljs-punctuation">:</span> <span class="hljs-string">single-node  #es单机模式</span><br>      <span class="hljs-attribute">TZ</span><span class="hljs-punctuation">:</span> <span class="hljs-string">Asia/Shanghai  #时区设置</span><br>      <span class="hljs-attribute">TAKE_FILE_OWNERSHIP</span><span class="hljs-punctuation">:</span> <span class="hljs-string">true  #解决 volumes 挂载权限问题</span><br>      <span class="hljs-attribute">ES_JAVA_OPTS</span><span class="hljs-punctuation">:</span> <span class="hljs-string">-Xms256m -Xmx256m ##jvm内存分配为256MB</span><br>    <span class="hljs-attribute">ulimits</span><span class="hljs-punctuation">:</span><br>      <span class="hljs-attribute">memlock</span><span class="hljs-punctuation">:</span><br>        <span class="hljs-attribute">soft</span><span class="hljs-punctuation">:</span> <span class="hljs-string">-1</span><br>        <span class="hljs-attribute">hard</span><span class="hljs-punctuation">:</span> <span class="hljs-string">-1</span><br>    <span class="hljs-attribute">volumes</span><span class="hljs-punctuation">:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">./elasticsearch/data:/usr/share/elasticsearch/data</span><br>  <span class="hljs-attribute">oap</span><span class="hljs-punctuation">:</span><br>    <span class="hljs-attribute">image</span><span class="hljs-punctuation">:</span> <span class="hljs-string">apache/skywalking-oap-server:8.5.0-es6</span><br>    <span class="hljs-attribute">container_name</span><span class="hljs-punctuation">:</span> <span class="hljs-string">skywalking-oap</span><br>    <span class="hljs-attribute">depends_on</span><span class="hljs-punctuation">:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">sky-elasticsearch</span><br>    <span class="hljs-attribute">links</span><span class="hljs-punctuation">:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">sky-elasticsearch</span><br>    <span class="hljs-attribute">restart</span><span class="hljs-punctuation">:</span> <span class="hljs-string">always</span><br>    <span class="hljs-attribute">ports</span><span class="hljs-punctuation">:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">11800:11800</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">12800:12800</span><br>    <span class="hljs-attribute">environment</span><span class="hljs-punctuation">:</span><br>      <span class="hljs-attribute">SW_STORAGE</span><span class="hljs-punctuation">:</span> <span class="hljs-string">elasticsearch</span><br>      <span class="hljs-attribute">SW_STORAGE_ES_CLUSTER_NODES</span><span class="hljs-punctuation">:</span> <span class="hljs-string">sky-elasticsearch:9200</span><br>      <span class="hljs-attribute">SW_HEALTH_CHECKER</span><span class="hljs-punctuation">:</span> <span class="hljs-string">default</span><br>      <span class="hljs-attribute">SW_TELEMETRY</span><span class="hljs-punctuation">:</span> <span class="hljs-string">prometheus</span><br>    <span class="hljs-attribute">healthcheck</span><span class="hljs-punctuation">:</span><br>      <span class="hljs-attribute">test</span><span class="hljs-punctuation">:</span> <span class="hljs-string">[&quot;CMD&quot;, &quot;./bin/swctl&quot;, &quot;ch&quot;]</span><br>      <span class="hljs-attribute">interval</span><span class="hljs-punctuation">:</span> <span class="hljs-string">30s</span><br>      <span class="hljs-attribute">timeout</span><span class="hljs-punctuation">:</span> <span class="hljs-string">10s</span><br>      <span class="hljs-attribute">retries</span><span class="hljs-punctuation">:</span> <span class="hljs-string">3</span><br>      <span class="hljs-attribute">start_period</span><span class="hljs-punctuation">:</span> <span class="hljs-string">40s</span><br>  <span class="hljs-attribute">ui</span><span class="hljs-punctuation">:</span><br>    <span class="hljs-attribute">image</span><span class="hljs-punctuation">:</span> <span class="hljs-string">apache/skywalking-ui:8.5.0</span><br>    <span class="hljs-attribute">container_name</span><span class="hljs-punctuation">:</span> <span class="hljs-string">skywalking-ui</span><br>    <span class="hljs-attribute">depends_on</span><span class="hljs-punctuation">:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">oap</span><br>    <span class="hljs-attribute">links</span><span class="hljs-punctuation">:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">oap</span><br>    <span class="hljs-attribute">restart</span><span class="hljs-punctuation">:</span> <span class="hljs-string">always</span><br>    <span class="hljs-attribute">ports</span><span class="hljs-punctuation">:</span><br>      <span class="hljs-bullet">-</span> <span class="hljs-string">8888:8080</span><br>    <span class="hljs-attribute">environment</span><span class="hljs-punctuation">:</span><br>      <span class="hljs-attribute">SW_OAP_ADDRESS</span><span class="hljs-punctuation">:</span> <span class="hljs-string">oap:12800</span><br></code></pre></td></tr></table></figure>

<p><code>docker-compose up -d</code>启动容器编排即可</p>
<p><code>docker-compose ps</code>查询容器状态</p>
<p><img src="https://files.mdnice.com/user/33721/efa8f22c-37d7-4260-9eb7-34fdf6045575.png" srcset="/img/loading.gif" lazyload alt="image"></p>
<p><code>浏览器打开ip:8888 进入skywalking的UI页面</code></p>
<p><img src="https://files.mdnice.com/user/33721/033347f1-20bc-4e8a-9655-612d250ac85f.png" srcset="/img/loading.gif" lazyload alt="image"></p>
<h2 id="下载和安装-python-的-agent"><a href="#下载和安装-python-的-agent" class="headerlink" title="下载和安装 python 的 agent"></a>下载和安装 python 的 agent</h2><p><img src="https://files.mdnice.com/user/33721/5f80799e-ecf6-464c-95ae-d90ec81c08b9.png" srcset="/img/loading.gif" lazyload alt="image"></p>
<p>python agent 安装文档：<a target="_blank" rel="noopener" href="https://skywalking.apache.org/docs/skywalking-python/latest/readme/">https://skywalking.apache.org/docs/skywalking-python/latest/readme/</a></p>
<p>注意：SkyWalking Python 代理需要 SkyWalking 8.0+ 和 Python 3.7+</p>
<h3 id="安装方式"><a href="#安装方式" class="headerlink" title="安装方式"></a>安装方式</h3><p><strong>PypI 安装</strong></p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs cmake"><br><span class="hljs-comment"># Install the latest version, using the default gRPC protocol to report data to OAP</span><br>pip <span class="hljs-keyword">install</span> <span class="hljs-string">&quot;apache-skywalking&quot;</span><br><br><span class="hljs-comment"># Install support for every protocol (gRPC, HTTP, Kafka)</span><br>pip <span class="hljs-keyword">install</span> <span class="hljs-string">&quot;apache-skywalking[all]&quot;</span><br><br><span class="hljs-comment"># Install the latest version, using the http protocol to report data to OAP</span><br>pip <span class="hljs-keyword">install</span> <span class="hljs-string">&quot;apache-skywalking[http]&quot;</span><br><br><span class="hljs-comment"># Install the latest version, using the kafka protocol to report data to OAP</span><br>pip <span class="hljs-keyword">install</span> <span class="hljs-string">&quot;apache-skywalking[kafka]&quot;</span><br><br><span class="hljs-comment"># Install a specific version x.y.z</span><br><span class="hljs-comment"># pip install apache-skywalking==x.y.z</span><br>pip <span class="hljs-keyword">install</span> apache-skywalking==<span class="hljs-number">0.1</span>.<span class="hljs-number">0</span>  <span class="hljs-comment"># For example, install version 0.1.0 no matter what the latest version is</span><br></code></pre></td></tr></table></figure>

<h3 id="Docker-安装"><a href="#Docker-安装" class="headerlink" title="Docker 安装"></a>Docker 安装</h3><p>SkyWalking Python 代理提供方便的 dockerfile 和图像，以便利用其自动引导功能轻松集成。</p>
<p>只需根据所需的代理版本、协议和 Python 版本从 Docker Hub 中提取 SkyWalking Python 映像即可。</p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs apache"><br><span class="hljs-attribute">FROM</span> apache/skywalking-python:<span class="hljs-number">0</span>.<span class="hljs-number">8</span>.<span class="hljs-number">0</span>-grpc-py3.<span class="hljs-number">10</span><br><br><span class="hljs-comment"># ... build your Python application</span><br><br><span class="hljs-comment"># If you prefer compact images (built from official Python slim image)</span><br><br><span class="hljs-attribute">FROM</span> apache/skywalking-python:<span class="hljs-number">0</span>.<span class="hljs-number">8</span>.<span class="hljs-number">0</span>-grpc-py3.<span class="hljs-number">10</span>-slim<br><br></code></pre></td></tr></table></figure>

<p>然后，您可以基于我们启用代理的 Python 映像构建您的 Python 应用程序映像，并在为您启用 SkyWalking 代理的情况下启动您的应用程序。请参阅我们的 容器化指南，了解有关集成和配置的更多说明。</p>
<h3 id="非倾入式安装【推荐】"><a href="#非倾入式安装【推荐】" class="headerlink" title="非倾入式安装【推荐】"></a>非倾入式安装【推荐】</h3><p><strong>SkyWalking Python 代理命令行界面 (sw-python CLI)</strong><br>现在，SkyWalking Python Agent CLI 是使用 Python 代理运行应用程序的推荐方式，该 CLI 经过充分测试并被所有代理 E2E 和插件测试使用。</p>
<p>在 0.7.0 之前的版本中，您至少需要将以下几行添加到您的应用程序中才能连接并运行代理，由于大量服务、DevOps 实践，这在许多情况下可能很乏味，并且在使用时可能会导致问题与预分叉服务器</p>
<figure class="highlight arduino"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs arduino">from skywalking <span class="hljs-keyword">import</span> agent, config<br>config.<span class="hljs-built_in">init</span>(SomeConfig)<br>agent.<span class="hljs-built_in">start</span>()<br></code></pre></td></tr></table></figure>

<p>SkyWalking Python 代理实现了一个命令行界面，可用于在部署期间将代理附加到您出色的应用程序，而无需更改任何应用程序代码，就像 SkyWalking Java 代理一样。<br>特别是有了新的自动 postfork 注入功能，您不再需要担心线程和 fork 不兼容的问题。</p>
<p>查看<strong>如何与 uWSGI 一起使用</strong>和<strong>如何与 Gunicorn 一起使用</strong>，了解 post_fork 的详细背景、为什么需要它们以及如何轻松克服 sw-pythonCLI 的麻烦。</p>
<p>如果 CLI 不适合您，您仍然应该阅读集成代理的传统方法。sw-python</p>
<p><strong>如何与 uWSGI 一起使用</strong>: <a target="_blank" rel="noopener" href="https://skywalking.apache.org/docs/skywalking-python/latest/en/setup/faq/how-to-use-with-uwsgi/">https://skywalking.apache.org/docs/skywalking-python/latest/en/setup/faq/how-to-use-with-uwsgi/</a></p>
<p><strong>如何与 Gunicorn 一起使用</strong>：<a target="_blank" rel="noopener" href="https://skywalking.apache.org/docs/skywalking-python/latest/en/setup/faq/how-to-use-with-gunicorn/">https://skywalking.apache.org/docs/skywalking-python/latest/en/setup/faq/how-to-use-with-gunicorn/</a></p>
<h3 id="使用方法"><a href="#使用方法" class="headerlink" title="使用方法"></a>使用方法</h3><p>通过 pip 成功安装 SkyWalking Python 代理 sw-python 后，将在您的环境中安装命令行脚本（首选虚拟环境）。</p>
<blockquote>
<p>运行 sw-python 看看它是否可用，您将需要通过环境变量传递配置。</p>
</blockquote>
<p>例如：<code>export SW_AGENT_COLLECTOR_BACKEND_SERVICES=localhost:11800</code></p>
<h3 id="选项-run"><a href="#选项-run" class="headerlink" title="选项 run_"></a>选项 run_</h3><p>CLI <code>sw-python</code>提供了一个 run 选项，您可以使用它来执行应用程序（以命令开头 python 或以路径上的基于 Python 的程序 gunicorn 开头），就像您正常调用它们一样，加上前缀，以下示例演示了用法。</p>
<p>如果您之前运行 Gunicorn&#x2F;uwsgi 应用程序的命令是：</p>
<p><code>gunicorn your_app:app --workers 2 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:8088</code></p>
<p>或者</p>
<p><code>uwsgi --die-on-term --http 0.0.0.0:5000 --http-manage-expect --master --workers 3 --enable-threads --threads 3 --manage-script-name --mount /=main:app</code></p>
<p>请将其更改为（该-p 选项在每个进程中启动一个代理，这是正确的行为）：</p>
<p>重要提示：如果对 uwsgi&#x2F;gunicorn 的调用以其他命令为前缀，则此方法将失败，因为代理当前将在索引 0 处查找命令行输入以确保安全，作为实验性功能。</p>
<p><code>sw-python run -p gunicorn your_app:app --workers 2 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:8088</code></p>
<p>或者</p>
<p><code>sw-python run -p uwsgi --die-on-term --http 0.0.0.0:5000 --http-manage-expect --master --workers 3 --enable-threads --threads 3 --manage-script-name --mount /=main:app</code></p>
<p>SkyWalking Python 代理很快就会与您的所有应用程序工作人员一起启动。</p>
<p>请注意，sw-python 只要是 PYTHONPATH 继承的，也可以使用生成的子进程 (os.exec*&#x2F;subprocess)。</p>
<p>此外，只要打开了应用程序分叉工作线程，sw-python 启动代理就可以很好地工作。（检测到 gunicorn 时会自动开启）os.forkSW_AGENT_EXPERIMENTAL_FORK_SUPPORT</p>
<h3 id="配置代理"><a href="#配置代理" class="headerlink" title="配置代理"></a>配置代理</h3><p>您通常需要提供除默认配置之外的其他配置。</p>
<h3 id="通过环境变量"><a href="#通过环境变量" class="headerlink" title="通过环境变量"></a>通过环境变量</h3><p>当前支持的方法是提供环境变量列表中列出和解释的环境变量。</p>
<h3 id="通过-sw-config-toml（待定）"><a href="#通过-sw-config-toml（待定）" class="headerlink" title="通过 sw-config.toml（待定）"></a>通过 sw-config.toml（待定）</h3><p>目前仅支持环境变量配置；toml 将实施可选配置。</p>
<p>启用 CLI 调试模式<br>请注意，CLI 是一项操作 Python 解释器引导行为的功能，可能存在不受支持的情况。</p>
<p>如果遇到意外问题，请通过在命令中添加-d 或–debug 标志来打开调试模式 sw-python，如下所示。</p>
<p>从：<code>sw-python run command</code></p>
<p>到：<code>sw-python -d run command</code></p>
<h3 id="附加说明"><a href="#附加说明" class="headerlink" title="附加说明"></a>附加说明</h3><p>当使用 执行命令时 sw-python run command，命令的 Python 解释器将拾取 SkyWalking 加载器模块。</p>
<p>将 SkyWalking Agent 附加到其他 Python 安装中的命令并不安全，因为不兼容的 Python 版本和不匹配的 SkyWalking 版本可能会导致问题。因此，任何尝试传递使用不同 Python 解释器&#x2F;环境的命令都不会启动 SkyWalking Python 代理，即使那里安装了另一个 SkyWalking Python 代理（无论版本如何），并且会强制退出并显示一条指示原因的错误消息。</p>
<h3 id="禁止生成的进程启动新代理"><a href="#禁止生成的进程启动新代理" class="headerlink" title="禁止生成的进程启动新代理"></a>禁止生成的进程启动新代理</h3><p>有时，您实际上并不需要代理来监视新进程中的任何内容（当它不是 Web 服务工作者时）。（这里我们指的是由 subprocess 和 os.exec*() 生成的进程，os.fork() 不受此标志控制，但是 experimental_fork_support）</p>
<p>如果您不需要为应用程序子进程加载代理，则可以通过设置环境变量来关闭该行为。</p>
<p>SW_AGENT_SW_PYTHON_BOOTSTRAP_PROPAGATE 到 False</p>
<p>请注意，自动引导程序取决于子进程继承的环境，因此在其前面添加新的 sitecustomize 路径或从中删除加载程序路径 PYTHONPATH 也可能会阻止代理在子进程中加载 ​​。</p>
<h3 id="已知的限制"><a href="#已知的限制" class="headerlink" title="已知的限制"></a>已知的限制</h3><ol>
<li>对于某些 shell 中涉及双引号的参数，CLI 可能无法正常工作。</li>
<li>CLI 和引导程序标准输出日志在 Windows shell 中可能会变得混乱。</li>
</ol>
<h2 id="接入-django-项目"><a href="#接入-django-项目" class="headerlink" title="接入 django 项目"></a>接入 django 项目</h2><p>新建 django 项目<br><code>django-admin startproject sky_django_uwsgi</code></p>
<p><strong>settings.py</strong></p>
<figure class="highlight capnproto"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs capnproto"><span class="hljs-keyword">from</span> sky_script.sky_middleware <span class="hljs-keyword">import</span> *<br><br>ALLOWED_HOSTS = [<span class="hljs-string">&quot;*&quot;</span>]<br></code></pre></td></tr></table></figure>

<p>新建<strong>init_sky</strong>文件</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs routeros"><span class="hljs-comment"># my_middleware.py</span><br>import os<br><br><span class="hljs-keyword">from</span> skywalking import agent,<span class="hljs-built_in"> config</span><br><span class="hljs-built_in"></span><br><br>def init_sky():<br>    agent_instance_name = f<span class="hljs-string">&#x27;&lt;some_good_name&gt;-child(&#123;os.getpid()&#125;)&#x27;</span><br><br>    config.init(<span class="hljs-attribute">agent_collector_backend_services</span>=<span class="hljs-string">&#x27;*.*.*.*:11800&#x27;</span>,<br>                <span class="hljs-attribute">agent_name</span>=<span class="hljs-string">&#x27;sky_django_uwsgi&#x27;</span>, <span class="hljs-attribute">agent_instance_name</span>=agent_instance_name)<br><br>    agent.start()<br><br></code></pre></td></tr></table></figure>

<p><img src="https://files.mdnice.com/user/33721/f814fac7-3b30-4adf-bbe2-a6d9e4aadc9a.png" srcset="/img/loading.gif" lazyload alt="image"></p>
<p><img src="https://files.mdnice.com/user/33721/782868ed-40d8-432d-bef7-e5942180c5f3.png" srcset="/img/loading.gif" lazyload alt="image"></p>
<p><img src="https://files.mdnice.com/user/33721/43575f49-8b53-45c0-b813-29dc24ff4945.png" srcset="/img/loading.gif" lazyload alt="image"></p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E7%9B%91%E6%8E%A7/" class="category-chain-item">监控</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E7%9B%91%E6%8E%A7/" class="print-no-link">#监控</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Python 项目微服务链路追踪监控利器：SkyWalking 全景解析与实战应用</div>
      <div>http://blog.xhweng.cn/2024/03/27/python_SkyWalking/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>xuehaoweng</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2024年3月27日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2024/03/27/Django%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E5%AE%9E%E7%8E%B0%E6%8C%87%E5%8D%97%EF%BC%9A%E6%8E%A2%E7%B4%A2%E9%AB%98%E6%95%88%E7%BC%96%E7%A8%8B%E7%9A%84%E5%A4%9A%E7%A7%8D%E9%80%94%E5%BE%84/" title="Django异步任务实现指南：探索高效编程的多种途径">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Django异步任务实现指南：探索高效编程的多种途径</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2024/03/27/Prometheus%E9%83%A8%E7%BD%B2TCP%E5%92%8CICMP%E6%9C%8D%E5%8A%A1%E6%8E%A2%E6%B5%8B%EF%BC%9A%E7%9B%91%E6%8E%A7%E7%9A%84%E8%89%BA%E6%9C%AF%E4%B8%8E%E7%A7%91%E5%AD%A6/" title="Prometheus部署TCP和ICMP服务探测：监控的艺术与科学">
                        <span class="hidden-mobile">Prometheus部署TCP和ICMP服务探测：监控的艺术与科学</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
    <!-- 备案信息 ICP for China -->
    <div class="beian">
  <span>
    <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
      皖ICP备2024038809号-2
    </a>
  </span>
  
    
      <span>
        <a
          href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=12345678"
          rel="nofollow noopener"
          class="beian-police"
          target="_blank"
        >
          
            <span style="visibility: hidden; width: 0">|</span>
            <img src="/img/police_beian.png" srcset="/img/loading.gif" lazyload alt="police-icon"/>
          
          <span>京公网安备12345678号</span>
        </a>
      </span>
    
  
</div>

  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
